<template>
	<view class="page">
		<view class="bg">
			<view class="bg_le">
				<view>{{caddie_info.user_money}}</view>
				<view>当前余额(元)</view>
			</view>
			<view class="bg_ri" @tap="withdrawal">
				<image src="/static/talent/user/withdrawal.png"></image>
			</view>
		</view>
		<view class="more">
			<view>近30天记录</view>
			<view @tap="getMore">查看全部</view>
		</view>
		<view class="list">
			<view class="listX" v-for="(v, k) in listData" :key="k">
				<view class="list_le">
					<view>{{v.change_type_value}}</view>
					<view>{{v.create_time}}</view>
				</view>
				<view :class="v.change_type == 1  || v.change_type == 5 ? 'list_ri2' : 'list_ri'">
					<text>{{v.change_money}}</text>
				</view>
			</view>
		</view>
		<view v-if="listData.length == 0" style="padding: 20rpx 0;">
			<u-empty text="没有更多了" mode="list"></u-empty>
		</view>
		<view style="padding: 20rpx 0;">
			<u-loadmore v-if="last_page > 1" :status="status" :icon-type="iconType" :load-text="loadText" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				caddie_info: '',
				is_payPaw: '',
				listData: [],
				last_page: 1,
				page: 1,
				refresh: false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多了'
				}
			}
		},
		onLoad() {

		},
		onShow() {
			this.page = 1
			this.refresh = true
			uni.showLoading({
				title: '加载中'
			})
			this.getBatInfo()
			this.payPassword()
			this.balanceInfo()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.refresh = true
			this.balanceInfo()
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			this.refresh = false
			setTimeout(() => {

				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.balanceInfo()
			}, 500)
		},
		methods: {
			// 获取余额
			getBatInfo() {
				this.$api.post(global.apiUrls.batWork, {

				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 1) {
						this.caddie_info = res.data.data.caddie_info
						this.caddie_info.user_money = (Math.round(this.caddie_info.user_money * 100) / 100).toFixed(0)
					} else {
						this.$message.info(res.data.msg)
					}
				})
			},
			// 判断是否设置支付密码
			payPassword() {
				this.$api.post(global.apiUrls.postUserCheck_pay_password, {

				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 1) {
						this.is_payPaw = res.data.data.withdraw_paw
					} else {
						this.$message.info(res.data.msg)
					}
				})
			},
			// 提现
			withdrawal() {
				if (this.is_payPaw == '') {
					uni.navigateTo({
						url: '/pages/index/setting/setPayPassword?type=' + 1
					})
				} else {
					uni.navigateTo({
						url: '/pages/user/wallet/withdraw'
					})

				}
			},
			// 获取消费记录
			balanceInfo() {
				this.$api.post(global.apiUrls.myBalanceList, {
					type: 1,
					page: this.page
				}).then(res => {
					// console.log(res)
					uni.hideLoading()
					uni.stopPullDownRefresh()
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page
						if (this.refresh) {
							this.listData = res.data.data.data
						} else {
							this.listData = this.listData.concat(res.data.data.data)

						}
						this.listData.forEach((v, k) => {
							v.change_money = v.change_money.substring(0, v.change_money.length - 3)
						})

					} else {
						this.$message.info(res.data.msg)
					}
				})
			},
			// 查看全部
			getMore() {
				uni.navigateTo({
					url: '/pages/user/user/balanceDetails'
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		background-color: #FFFFFF;
		color: #333333;

		.bg {
			height: 280rpx;
			width: 100%;
			background: url(../../../static/talent/user/balence_bg.png) no-repeat;
			background-size: 100% 100%;
			display: flex;

			.bg_le {
				flex: 5;
				padding-top: 58rpx;

				view:first-child {
					font-size: 72rpx;
					color: #FFFFFF;
					margin-bottom: 24rpx;
				}

				view:last-child {
					font-size: 28rpx;
					color: #FFFFFF;
					font-weight: 400;
				}

				margin-left: 74rpx;
			}

			.bg_ri {
				flex: 5;
				text-align: right;
				padding-top: 92rpx;

				image {
					width: 170rpx;
					height: 64rpx;
				}
			}
		}

		.more {
			height: 90rpx;
			line-height: 90rpx;
			padding: 0 32rpx;
			background: #f2f2f1;
			overflow: hidden;

			view:first-child {
				float: left;
				font-size: 28rpx;
				color: #6B6F73;
			}

			view:last-child {
				float: right;
				font-size: 24rpx;
				color: #999999;
			}
		}

		.list {
			padding: 0 32rpx;

			.listX {
				padding: 32rpx 0;
				display: flex;
				border-bottom: 1rpx solid #f2f2f1;

				.list_le {
					width: 80%;

					view:first-child {
						font-size: 32rpx;
						color: #1C2921;
						margin-bottom: 24rpx;
					}

					view:last-child {
						font-size: 24rpx;
						color: #999999;
					}
				}

				.list_ri {
					text-align: right;
					width: 20%;
					padding-top: 32rpx;
					color: #EB5D03;

					text:first-child {
						font-size: 32rpx;
					}

					text:last-child {
						font-size: 32rpx;
						font-weight: bold;
					}
				}

				.list_ri2 {
					text-align: right;
					width: 20%;
					padding-top: 32rpx;
					color: #333333;

					text:first-child {
						font-size: 32rpx;
					}

					text:last-child {
						font-size: 32rpx;
						font-weight: bold;
					}
				}
			}
		}
	}
</style>
